<?php

namespace Admin\Entity;

use Doctrine\ORM\Mapping as ORM;
use Zend\InputFilter\InputFilter;
use Zend\InputFilter\InputFilterAwareInterface;
use Zend\InputFilter\InputFilterInterface;
use Zend\Validator\File\Size;

/**
 * Product
 *
 * @ORM\Table(name="product")
 * @ORM\Entity
 */
class Product implements InputFilterAwareInterface
{
	
	protected $inputFilter;
    /**
     * @var integer
     *
     * @ORM\Column(name="id", type="integer", nullable=false)
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="IDENTITY")
     */
    private $id;

    /**
     * @var string
     *
     * @ORM\Column(name="title", type="string", length=255, nullable=false)
     */
    private $title;

    /**
     * @var string
     *
     * @ORM\Column(name="title_slug", type="string", length=255, nullable=false)
     */
    private $titleSlug;

    /**
     * @var integer
     *
     * @ORM\Column(name="category_id", type="integer", nullable=false)
     */
    private $categoryId;

    /**
     * @var string
     *
     * @ORM\Column(name="des_short", type="string", length=1000, nullable=false)
     */
    private $desShort;

    /**
     * @var string
     *
     * @ORM\Column(name="description", type="text", nullable=false)
     */
    private $description;

    /**
     * @var string
     *
     * @ORM\Column(name="thumbnail", type="string", length=255, nullable=false)
     */
    private $thumbnail;

    /**
     * @var integer
     *
     * @ORM\Column(name="brand_id", type="integer", nullable=true)
     */
    private $brandId;

    /**
     * @var integer
     *
     * @ORM\Column(name="price", type="integer", nullable=false)
     */
    private $price;

    /**
     * @var boolean
     *
     * @ORM\Column(name="promotions", type="boolean", nullable=false)
     */
    private $promotions;

    /**
     * @var boolean
     *
     * @ORM\Column(name="active", type="boolean", nullable=false)
     */
    private $active;

    /**
     * @var integer
     *
     * @ORM\Column(name="view", type="integer", nullable=false)
     */
    private $view;

    /**
     * @var integer
     *
     * @ORM\Column(name="member_id", type="integer", nullable=false)
     */
    private $memberId;

    /**
     * @var integer
     *
     * @ORM\Column(name="member_update", type="integer", nullable=true)
     */
    private $memberUpdate;

    /**
     * @var \DateTime
     *
     * @ORM\Column(name="create_time", type="datetime", nullable=false)
     */
    private $createTime;

    /**
     * @var \DateTime
     *
     * @ORM\Column(name="update_time", type="datetime", nullable=false)
     */
    private $updateTime;



    /**
     * Get id
     *
     * @return integer 
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * Set title
     *
     * @param string $title
     * @return Product
     */
    public function setTitle($title)
    {
        $this->title = $title;

        return $this;
    }

    /**
     * Get title
     *
     * @return string 
     */
    public function getTitle()
    {
        return $this->title;
    }

    /**
     * Set titleSlug
     *
     * @param string $titleSlug
     * @return Product
     */
    public function setTitleSlug($titleSlug)
    {
        $this->titleSlug = $titleSlug;

        return $this;
    }

    /**
     * Get titleSlug
     *
     * @return string 
     */
    public function getTitleSlug()
    {
        return $this->titleSlug;
    }

    /**
     * Set categoryId
     *
     * @param integer $categoryId
     * @return Product
     */
    public function setCategoryId($categoryId)
    {
        $this->categoryId = $categoryId;

        return $this;
    }

    /**
     * Get categoryId
     *
     * @return integer 
     */
    public function getCategoryId()
    {
        return $this->categoryId;
    }

    /**
     * Set desShort
     *
     * @param string $desShort
     * @return Product
     */
    public function setDesShort($desShort)
    {
        $this->desShort = $desShort;

        return $this;
    }

    /**
     * Get desShort
     *
     * @return string 
     */
    public function getDesShort()
    {
        return $this->desShort;
    }

    /**
     * Set description
     *
     * @param string $description
     * @return Product
     */
    public function setDescription($description)
    {
        $this->description = $description;

        return $this;
    }

    /**
     * Get description
     *
     * @return string 
     */
    public function getDescription()
    {
        return $this->description;
    }

    /**
     * Set thumbnail
     *
     * @param string $thumbnail
     * @return Product
     */
    public function setThumbnail($thumbnail)
    {
        $this->thumbnail = $thumbnail;

        return $this;
    }

    /**
     * Get thumbnail
     *
     * @return string 
     */
    public function getThumbnail()
    {
        return $this->thumbnail;
    }

    /**
     * Set brandId
     *
     * @param integer $brandId
     * @return Product
     */
    public function setBrandId($brandId)
    {
        $this->brandId = $brandId;

        return $this;
    }

    /**
     * Get brandId
     *
     * @return integer 
     */
    public function getBrandId()
    {
        return $this->brandId;
    }

    /**
     * Set price
     *
     * @param integer $price
     * @return Product
     */
    public function setPrice($price)
    {
        $this->price = $price;

        return $this;
    }

    /**
     * Get price
     *
     * @return integer 
     */
    public function getPrice()
    {
        return $this->price;
    }

    /**
     * Set promotions
     *
     * @param boolean $promotions
     * @return Product
     */
    public function setPromotions($promotions)
    {
        $this->promotions = $promotions;

        return $this;
    }

    /**
     * Get promotions
     *
     * @return boolean 
     */
    public function getPromotions()
    {
        return $this->promotions;
    }

    /**
     * Set active
     *
     * @param boolean $active
     * @return Product
     */
    public function setActive($active)
    {
        $this->active = $active;

        return $this;
    }

    /**
     * Get active
     *
     * @return boolean 
     */
    public function getActive()
    {
        return $this->active;
    }

    /**
     * Set view
     *
     * @param integer $view
     * @return Product
     */
    public function setView($view)
    {
        $this->view = $view;

        return $this;
    }

    /**
     * Get view
     *
     * @return integer 
     */
    public function getView()
    {
        return $this->view;
    }

    /**
     * Set memberId
     *
     * @param integer $memberId
     * @return Product
     */
    public function setMemberId($memberId)
    {
        $this->memberId = $memberId;

        return $this;
    }

    /**
     * Get memberId
     *
     * @return integer 
     */
    public function getMemberId()
    {
        return $this->memberId;
    }

    /**
     * Set memberUpdate
     *
     * @param integer $memberUpdate
     * @return Product
     */
    public function setMemberUpdate($memberUpdate)
    {
        $this->memberUpdate = $memberUpdate;

        return $this;
    }

    /**
     * Get memberUpdate
     *
     * @return integer 
     */
    public function getMemberUpdate()
    {
        return $this->memberUpdate;
    }

    /**
     * Set createTime
     *
     * @param \DateTime $createTime
     * @return Product
     */
    public function setCreateTime($createTime)
    {
        $this->createTime = $createTime;

        return $this;
    }

    /**
     * Get createTime
     *
     * @return \DateTime 
     */
    public function getCreateTime()
    {
        return $this->createTime;
    }

    /**
     * Set updateTime
     *
     * @param \DateTime $updateTime
     * @return Product
     */
    public function setUpdateTime($updateTime)
    {
        $this->updateTime = $updateTime;

        return $this;
    }

    /**
     * Get updateTime
     *
     * @return \DateTime 
     */
    public function getUpdateTime()
    {
        return $this->updateTime;
    }
    
    /**
     * Convert from object to array
     * @return multitype:
     */
    public function getArrayCopy() {
    	return get_object_vars($this);
    }
    
    public function exchangeArray($data = array()) {
    	$this->id = $data['id'];
    	$this->title = $data['title'];
    	$this->title_slug = $data['title_slug'];
    	$this->category_id = $data['category_id'];
    	$this->des_short = $data['des_short'];
    	$this->description = $data['description'];
    	$this->thumbnail = $data['thumbnail'];
    	$this->brand_id = $data['brand_id'];
    	$this->price = $data['price'];
    	$this->promotions = $data['promotions'];
    	$this->active = $data['active'];
    	$this->view = $data['view'];
    	$this->member_id = $data['member_id'];
    	$this->member_update = $data['member_update'];
    	$this->create_time = $data['create_time'];
    	$this->update_time = $data['update_time'];
    }
    
    
    public function setInputFilter(InputFilterInterface $inputFilter) {
    	throw new \Exception("Not use");
    }
    
    public function getInputFilter() {
    	if(!$this->inputFilter) {
    		$inputFilter = new InputFilter();
    		
    		$inputFilter->add(array(
    				'name' => 'id',
    				'required' => true,
    				'filters' => array(
    					array('name' => 'Int'),
    				),
    		));
    		
    		$inputFilter->add(array(
    				'name' => 'title',
    				'required' => true,
    				'filters' => array(
    					array('name' => 'StripTags'),
    					array('name' => 'StringTrim'),
    				),
    				'validators' => array(
						array(
							'name' => 'StringLength',
							'options' => array(
								'encoding'  => 	'UTF-8',
								'min'		=> 	'4',
								'max' 		=>	'255',
							),
						),    				
    				),
    		));
    		
    		$inputFilter->add(array(
    				'name' => 'des_short',
    				'required' => true,
    				'filters' => array(
    						array('name' => 'StripTags'),
    						array('name' => 'StringTrim'),
    				),
    				'validators' => array(
    						array(
    								'name' => 'StringLength',
    								'options' => array(
    										'encoding'  => 	'UTF-8',
    										'min'		=> 	'10',
    										'max' 		=>	'1000',
    								),
    						),
    				),
    		));
    		
    		$inputFilter->add(array(
    				'name' => 'description',
    				'required' => true,
    				'filters' => array(
    						array('name' => 'StripTags'),
    						array('name' => 'StringTrim'),
    				),
    				'validators' => array(
    						array(
    								'name' => 'StringLength',
    								'options' => array(
    										'encoding'  => 	'UTF-8',
    										'min'		=> 	'10',
    								),
    						),
    				),
    		));
    		
    		$inputFilter->add(array(
    				'name' => 'thumbnail',
    				'required' => true,
    				'validators' => array(
    						array(
    								'name' => 'Zend\Validator\File\Size',
    								'options' => array(
    										'min'	=>	'200kB',
    										'max'	=>	'6MB', 
    								),
    						),
    						array(
    								'name'	=>	'Zend\Validator\File\Extension',
    								'options' => array(
    										'extension'	=>	array('png', 'jpg'),
    								),
    						),
    				),
    		));
    		
    		$inputFilter->add(array(
    				'name' => 'category_id',
    				'required' => true,
    				'filters' => array(
    						array('name' => 'Int'),
    				),
    		));
    		
    		$inputFilter->add(array(
    				'name' => 'brand_id',
    				'required' => true,
    				'filters' => array(
    						array('name' => 'Int'),
    				),
    		));
    		
    		$inputFilter->add(array(
    				'name' => 'active',
    				'required' => true,
    				'filters' => array(
    						array('name' => 'Int'),
    				),
    		));
    	}
    }
}
